<script>
import { mapMutations, mapActions, mapState } from "vuex";
var qs = require("qs");
var userInfo = uni.getStorageSync("USER_INFO");
var loginUserInfo = uni.getStorageSync("LOGIN_USER_INFO");
export default {
  onLaunch: function(opitons) {
    if (userInfo) {
      this.changUserInfo(userInfo);
    }
    if (loginUserInfo) {
      this.changLoginInfo(loginUserInfo);
    }
  },
  onShow: function(opitons) {
    this.setSharCode(opitons);
  },
  onHide: function() {
    console.log("App Hide");
    // uni.removeStorageSync('TOKEN');
  },
  watch: {
    token(n) {
      this.loggedinUserInfo();
    },
  },
  computed: {
    ...mapState(["token"]),
  },
  methods: {
    ...mapActions(["loggedinUserInfo"]),
    ...mapMutations(["changUserInfo", "changShareId", "changLoginInfo"]),
    postShareClick(share_code) {
      this.$api.postShareClick({ share_code });
    },
    getShareInfo(share_code) {
      return this.$api.getShareInfo({ share_code }).then((res) => {
        if (res.code == 200) {
          return res.data.user_id;
        }
      });
    },
    async setSharCode(opitons) {
      let {
        query: { shareCode, scene },
      } = opitons;
      let qrScene = qs.parse(decodeURIComponent(scene));
      let code = shareCode || qrScene.b;

      if (code) {
        console.log(code);
        // const shareUserId = await this.getShareInfo(code);
        this.changShareId(code);
        // if (shareUserId && userInfo.id != shareUserId) {
        this.postShareClick(code);
        // }
      }
    },
  },
};
</script>

<style lang="scss">
@import '@/wxcomponents/vant/common/index.css';
.img-size-100 {
  display: block;
  width: 100%;
  height: 100%;
}
/*每个页面公共css */
button::after {
  border: none;
}
button {
  background-color: transparent;

  padding-left: 0;

  padding-right: 0;

  line-height: inherit;
}
.nav-bar {
  background: linear-gradient(
    270deg,
    rgba(44, 172, 255, 1) 0%,
    rgba(40, 123, 252, 1) 100%
  );
}

rich-text .rich-img,
rich-text .wscnph {
  width: 100% !important;
  height: auto;
  vertical-align: bottom;
}
</style>
